/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package service;

import dao.NewsDao;
import dao.NewsDaoImpl;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import myUtils.page.Result;
import po.News;

/**
 *
 * @author sony
 */
public class NewsServiceImpl implements NewsService{

    private NewsDao newsDao;

    public void setNewsDao(NewsDaoImpl newsDao) {
        this.newsDao = newsDao;
    }

    public void addNews(News news) {
        try {
            newsDao.save(news);
        } catch (Exception ex) {
            Logger.getLogger(NewsServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public News getNews(int id) {
        return newsDao.getNews(id);
    }

    public void deleteNews(int id) {
        try {
            newsDao.deleteNews(id);
        } catch (Exception ex) {
            Logger.getLogger(NewsServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public List getLatestNews(int n) {
        return newsDao.getLatestNews(n);
    }

    public boolean isAuthor(int newsId, int userId) {
        return newsDao.isAuthor(newsId, userId);
    }

    public void updateNews(News news) {
        newsDao.updateNews(news);
    }

    public Result getAllNews(int page) {
        return newsDao.getAllNews(page);
    }

}
